package study.springcloud.gateway.support.cros;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

@Slf4j
@Configuration
public class _1_CorsConfig {

//    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration cfg = new CorsConfiguration();
        //头部
        cfg.addAllowedHeader("*");
        //方法
        cfg.addAllowedMethod("*");
        //来源
        cfg.addAllowedOrigin("*");
        //
        cfg.setAllowCredentials(true);

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", cfg);
        return new CorsWebFilter(source);
    }
}
